package com.fruit.system.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import lombok.Data;

@Entity
@Table(name="SYS_MENU")
@Data
public class Menu implements Serializable,Comparable<Menu>
{
	private static final long serialVersionUID = -2818359800944829784L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	//菜单名称
	private String name;
	
	//菜单描述
	private String description;
	
	//菜单权限位(权限分组)
	private Integer menuPos;
	
	//权限码
	private Long menuCode;
	
	//菜单图标
	private String icon;
	
	//路径
	private String url;
	
	//是否启用该菜单，默认启用
	private Boolean menuEnabled=Boolean.TRUE;
	
	//菜单排序号，排序号越大，该菜单在页面上显示时越靠前
	private Integer orderNum=100;
	
	//该菜单是否默认展开，默认不展开
	private Boolean initOpened=Boolean.FALSE;
	
	//上级菜单
	@ManyToOne
	@JoinColumn(name="pid")
	private Menu parent;
	
	//子菜单
	@Transient
	private List<Menu> children;
	
	//子菜单数目，用于快速判断该菜单是否有子菜单(即该菜单是否是叶子菜单)
	private Boolean isLeaf=Boolean.TRUE;
	
	@Transient
	private Integer privilegeId;

	//用于菜单排序的比较器
	@Override
	public int compareTo(Menu menu)
	{
		if(this.getOrderNum()>menu.getOrderNum())
			return 1;
		else if(this.getOrderNum()<menu.getOrderNum())
			return -1;
		return 0;
	}
}
